package ModelApplication;

import java.io.File;
import java.text.DecimalFormat;

import UtilsApplication.ChartTypes;
import UtilsApplication.WavFile;

public class Sound {

    double []  audio;
    double [] envelope;
    File file;
    String methodProcessing = "";
    String name = "";
    Double executionTime;
    WavFile wavFile;
    double baseFreq;
    ChartTypes chartType = ChartTypes.TIME_AMPLITUDE;
    DecimalFormat f = new DecimalFormat("##.00");

    public Sound(double [] audio, WavFile wavFile, File file ) {
        this.file = file;
        this.audio = audio;
        this.wavFile = wavFile;
    }

    public Sound(double [] audio, WavFile wavFile, File file, String methodProcessing, String name, String additionalName) {
        this(audio, wavFile, file);
        this.methodProcessing = methodProcessing;
        this.methodProcessing = methodProcessing;
        this.name = name.substring( 0, name.length() - 4 ) + "_" + methodProcessing + "_" +
                additionalName +
                "_" + name.substring( name.length() - 4 );
    }
    
    public Sound(double [] audio, WavFile wavFile, File file, String methodProcessing, String name, String additionalName, ChartTypes chartType) {
        this(audio, wavFile, file, methodProcessing, name, additionalName);
        this.chartType = chartType;
    }

    public double [] getAudio() {
        return audio;
    }


    public String getName() {
        if(file == null) {
            return name;
        }
        return file.getName();
    }

    public String getMethodProcessing() {
        return methodProcessing;
    }

    public File getFile() {
        return file;
    }

    public Double getExecutionTime() {
        return executionTime;
    }

    public void setExecutionTime( Double executionTime ) {
        this.executionTime = executionTime;
    }

    public WavFile getWavFile() {
        return wavFile;
    }

    public void setWavFile( WavFile wavFile ) {
        this.wavFile = wavFile;
    }
    
    public void setAudio(double [] audio) {
        this.audio = audio;
    }

    public Sound clone() {
        Sound cloneSound = new Sound(audio, wavFile, file);
        cloneSound.methodProcessing = new String(methodProcessing);
        cloneSound.name = new String(name);
        return cloneSound;
    }

    public double getBaseFreq() {
        return baseFreq;
    }

    public void setBaseFreq( double baseFreq ) {
        this.baseFreq = baseFreq;
    }
    
    public String getBaseFreqString() {
        if(baseFreq==0.0) {
            return "";
        } else {
            return f.format(baseFreq); 
        }
    }

    public ChartTypes getChartType() {
        return chartType;
    }

    public void setChartType( ChartTypes chartType ) {
        this.chartType = chartType;
    }

    public double[] getEnvelope() {
        return envelope;
    }

    public void setEnvelope( double[] envelope ) {
        this.envelope = envelope;
    }
}
